namespace game {
	export namespace gameConfig {
		export class GoodsInfo {

			private list:Array<string>;
			public id:number;
			public Name:string;
			public iconName:string;
			public IconType:number;
			public goodsType:number;
			public value:number;
			public DropRate:number;
			public LevelLimit:string;
			public Des:string;

			public Decode(list:Array<string>):void
			{
				this.list = list;
				for(let i = 0; i < list.length; i++)
				{
					if(i == 0)
					{
						this.id = ~~this.list[0];
					}
					if(i == 1)
					{
						this.Name = this.list[1];
					}
					if(i == 2)
					{
						this.iconName = this.list[2];
					}
					if(i == 3)
					{
						this.IconType = ~~this.list[3];
					}
					if(i == 4)
					{
						this.goodsType = ~~this.list[4];
					}
					if(i == 5)
					{
						this.value = ~~this.list[5];
					}
					if(i == 6)
					{
						this.DropRate = ~~this.list[6];
					}
					if(i == 7)
					{
						this.LevelLimit = this.list[7];
					}
					if(i == 8)
					{
						this.Des = this.list[8];
					}
				}
			}

			public DecodeConfigItem():void
			{
				for (let i = 0; i < this.list.length; i++)
				{
				}
				this.list = null;
			}


			public static Configs:Array<GoodsInfo> = new Array<GoodsInfo>();

			public static GetConfig(key:number):GoodsInfo
			{
				for(let i = 0,list = GoodsInfo.Configs; i < list.length; i++)
				{
					if(list[i].id == key)
					{
						return list[i];
					}
				}
				return null;
			}

			public static DecodeTable(str:string):void
			{
				let configs = GoodsInfo.Configs;
				configs.length = 0;
				str = lib.StringDo.replaceString(str, '\r', '\n');
				str = lib.StringDo.replaceString(str, "\n\n", '\n');
				var list:Array<Array<string>> = CSV.Parse(str);
				if(!GoodsInfo.isType(list[0][0])) list.splice(0,1);
				for(let i = 2,len = list.length; i < len; i++)
				{
					let item= new GoodsInfo();
					item.Decode(list[i]);
					configs.push(item);
				}
			}

			public static GetConfigWidth(paramName:string,value:any):GoodsInfo
			{
				for (let i = 0,configs = GoodsInfo.Configs; i < configs.length; i++)
				{
					let val = (configs[i] as any)[paramName];
					let flag = false;
					if (typeof val == "string")
					{
						flag = value == val ? true : false;
					}
					else
					{
						flag = val == value;
					}
					if (flag)
					{
						return configs[i];
					}
				}
				return null;
			}

			public static isType(str:string):boolean {
				if(str[0] == '(')
				{
					str = str.slice(str.indexOf(')') + 1,str.length)
					if(str == 'int' || str == 'number' || str == 'string') return true
				}
				if(str.slice(0,'Array'.length) == 'Array')
				{
					str = str.slice('Array('.length,str.length-1);
					if(str == 'int' || str == 'number' || str == 'string') return true;
				}
				if(str == 'int' || str == 'number' || str == 'string') return true;
				return false;
			}
			public static DecodeTableItem():void
			{
				for(let i = 0,len = GoodsInfo.Configs.length; i < len; i++)
				{
					GoodsInfo.Configs[i].DecodeConfigItem();
				}
			}

		}
	}
}